home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / randgr.zip / RANDGRID.DOC < prev    next >
Text File  |  1991-08-04  |  7KB  |  185 lines

  1.                                  RandGrid 1.0
  2.                        Copyright 1991 Nelson Ford, PsL
  3.                     P.O.Box 35705  Houston, TX 77235-5705
  4.  
  5.  
  6.                                    LICENSE
  7.  
  8. 1. You may freely use and distributed this code in applications in which
  9.      this code makes up a small part of the program.
  10.  
  11. 2. You may freely distribute this code to other VB programmers, including
  12.      uploading it to BBS's or for a disk fee, as long as all related files
  13.      are distributed together and without any changes.
  14.  
  15. All I ask for the use of this code is that if you find a better way to do
  16. something than the methods I've used, I would appreciate your letting me know.
  17.  
  18.  
  19.  
  20.                                  REQUIREMENTS
  21.  
  22. Visual Basic is required, of course, and GRID.VBX.
  23.  
  24. GRID.VBX is not included with this set of files. It is available on the MSLANG
  25. Forum's Data Libraries for downloading or you can get them on disk from PsL.
  26. (See the end of this file.)
  27.  
  28.  
  29.                                    PURPOSE
  30.  
  31. This is a sample application whose only purpose is to illustrate the coding
  32. needed to use a Random Access file in conjunction with a Grid Control. Even if
  33. you are using one but not the other, this sample code should come in handy.
  34.  
  35. The code in this program is almost identical to the code in the HugeGrid
  36. program that links a huge array to a random access file. My testing on a
  37. 386-33 with a 1-meg disk cache shows that the response time when using a
  38. random access file instead of a Huge Array is close enough to the same to make
  39. using the random access file preferable.
  40.  
  41. (Note: One thing I didn't do in this sample program is save the Pointers to
  42. disk when done. You'll need to do that in your own applications, obviously.)
  43.  
  44.  
  45.                                  INTRODUCTION
  46.  
  47. The Huge Array DLL and the Grid Control VBX were produced by Microsoft and
  48. given to beta testers, but not included with Visual Basic when released.
  49.  
  50. It appears that they are bug-free, but probably were not included because they
  51. are not very robust. For example, getting Text out of a Grid cell by having to
  52. change the Grid.Row and Grid.Col is a very inefficient way to do things,
  53. neither is having to access a Huge Array like you would a data file.
  54.  
  55. Nevertheless, if you HAVE to have either an array larger than 64k (VB's usual
  56. limit) or a Grid control - you'll be glad that MS decided to release these to
  57. the public as freebies.
  58.  
  59.  
  60.                         HUGE ARRAY VS RANDOM DATA FILE
  61.  
  62. As you will see, sorting a 5000-record file takes a lot of time. However, in
  63. your own application, you would presumably be updating pointers each time you
  64. added a record, and would never have to sort the data.
  65.  
  66. With a sufficiently large disk cache, a random access file appears to be about
  67. as fast as the Huge Array and has the advantage of being more secure, since
  68. data is written to the disk when added or deleted. However, if your user is
  69. not using a large enough cache, then performance could be seriously degraded
  70. by using a random access disk file.
  71.  
  72. Because getting data to and from a Huge Array is more like accessing a Random
  73. access data file than using an actual in-memory data array, the routines for
  74. both are nearly identical.
  75.  
  76.  
  77.                                 DOCUMENTATION
  78.  
  79. RANDGRID.FRM/.BAS - These files should be put in a subdirectory off your VB
  80. subdirectory.
  81.  
  82. GRID.VBX - This file should go in your VB subdirectory.
  83.  
  84. RANDGRID.FRM -
  85.  
  86. General
  87. DecrLastEl & IncrLastEl
  88.  
  89. When you delete an entry, several pointers have to be adjusted. This Sub
  90. makes sure that everything gets done.
  91.  
  92.  
  93. General
  94. Sub FillGrid(StartPt, StopPt, StartRow)
  95.  
  96. This routine gets data from the File and puts it in the grid.
  97. StartPt and StopPt are the pointer numbers to start and stop with.
  98. StartRow says what row of the grid to start with.
  99.  
  100.  
  101. General
  102. Function GetEl(x)
  103.  
  104. Gets the record from the file that Pointer(x) points to.
  105. You could format or otherwise manipulate the data at this point if needed.
  106.  
  107.  
  108. General
  109. ScrollUp & ScrollDown
  110. Lets you scroll selected rows in the Grid up or down. Given the kludgy way
  111. that data has to moved from one Grid cell to another, it may be just as quick
  112. to use the FillGrid routine to read the data in from the File again, and
  113. it would save all this code.
  114.  
  115.  
  116. Form
  117. Load:
  118.  
  119. In setting up your grids, you may have to experiment (going back and forth
  120. between design and run-time) to find the desired column widths, since I
  121. haven't found any way to change them during design time.
  122.  
  123. Most of the VScroll values shown can be set at design time. They are included
  124. here to make them easier to see.
  125.  
  126. For ease of coming up with a lot of different text, numbers were used to fill
  127. the array. However, these ARE strings and when sorted, they are sorted as
  128. strings, not as numbers. (So you will see 1.1 10.1 100.1 ... 2.1 20.1, etc.)
  129.  
  130. If you enter a number in the Text box and select Insert, it will be entered
  131. alphabetically, not numerically. You could easily change the code to treat the
  132. data as numbers rather than text simply by using VAL() everywhere that data
  133. variables are used.
  134.  
  135. After loading up the array, the end of the array is displayed in the Grid. You
  136. could just as easily pick any other part of the array for the initial display,
  137. but don't forget to change Vscroll1.Value accordingly. (eg: If you display
  138. elements 1 - 10, set Vscroll1.Value to 10.)
  139.  
  140. Form
  141. B_Sort
  142. This is a QuickSort algorithm, which is one of the fastest general sorting
  143. algorithm available. Although numeric data is used for ease of filling up an
  144. array with different data, the numbers are store as strings and will be sorted
  145. in string order. (eg: 10 100 1000 before 20)
  146.  
  147. Form
  148. B_Del
  149. Deletes a record from the File. To save time, the record is not actually
  150. removed from the File. An array (Deleted) is set up for keeping track of
  151. deleted records and reusing that space on subsequent Adds.
  152.  
  153. Form
  154. B_Find
  155. Does a binary search of the file for a specified record. The sample routine
  156. will only search for data in the first column. In an application, you could
  157. set up pointers for as many columns as you wish.
  158.  
  159. Form
  160. B_Insert
  161. This is an alphabetic insert. It calls B_Find and then inserts the new data.
  162. This took a lot of time to work out the special cases, such as inserting a
  163. number at the beginning or end of the file.
  164.  
  165.  
  166.  
  167.                             WHERE TO GET VB STUFF
  168.  
  169. This program was written by Nelson Ford, PsL.
  170.  
  171. You can find a lot of routines, sample programs, custom controls, and DLL's on
  172. Microsoft's MSLANG forum on CompuServe.
  173.  
  174. My company, Public (software) Library, also distributes a lot of VB goodies
  175. and programs written with VB. Call or write for a free copy of our monthly
  176. magazine and catalog:
  177.  
  178.                           Public (software) Library
  179.                                 P.O.Box 35705
  180.                             Houston, TX 77235-5705
  181.                              Orders: 800-242-4PsL
  182.                           Tech Support: 713-524-6394
  183.                               FAX: 713-524-6398
  184.                                 CIS: 71355,470
  185.